[Doing it Wrong] Auto Boxing of primitives

Posted by Jonathan on Stack Overflow See other posts from Stack Overflow or by Jonathan
Published on 2010-03-19T12:25:02Z Indexed on 2010/03/19 12:31 UTC
Read the original article Hit count: 244

Filed under:

I can't seem to figure out how to get Objective-c to auto box my primitives.

I assumed that i would be able to do the following

NSString* foo = @"12.5";
NSNumber* bar;

bar = [foo floatValue];

However i find that i have used to the more verbose method of

NSString* foo = @"12.5";
NSNumber* bar;

bar = [NSNumber numberWithFloat:[foo floatValue]];

Am i doing it wrong or is this as good as it gets?

© Stack Overflow or respective owner

Related posts about objective-c